<admintpl file="header"/>
<body class="J_scroll_fixed">
<style>
#content td{ line-height:24px;  text-align:center;  vertical-align:middle;}
.hidden{ display:none;}
</style>
<div class="wrap jj">
  <ul class="nav nav-tabs">
     <li><a href="{:U('Product/index')}">产品列表</a></li>
     <li class="active"><a href="{:U('Product/attribute',array('pid'=>$pid))}"  target="_self">属性信息</a></li>
  </ul>
   
  <div class="common-form">
    <div class="table_list">
        <div class="row">
            <div class="span10">
            	<table id="content" class="table table-bordered table-hover"><tr><td>正在加载...</td></tr></table>
            	<button type="button" class="btn btn-primary" id="att_add">增加属性</button>
            </div>
            <div class="span2">
				<div>
				<input type="text" id="newid" value="" placeholder="被拷贝的产品ID" style="width:90%"/><br/>
				<button type="button" id="submit2" class="btn btn-primary">拷贝</button>
			  </div>
            	<div id="json"></div>
            </div>
        </div>
    </div>
  <div class="form-actions">
        <button type="button" id="submit" class="btn btn-primary">提交</button>
        <a class="btn" href="{:U('Product/index')}">返回</a>
  </div>


</div>
<script type="text/javascript" src="__ROOT__/statics/js/common.js"></script>
<script type="text/javascript" src="__ROOT__/statics/js/product_att.js"></script>
<script>
$(document).ready(function(){
	$("#att_add").on("click",function(){
		new_att('content');	
	});
	$("#submit").on("click",function(){
		var contents = $('#content').find('tr');
		console.log(contents);return false;
		if(contents.length>0)
		{
			var temp = [];
			contents.each(function(index){
				var x = JSON.parse($('.hidden').eq(index).html());
				temp.push(x);//属性数组集合
			});
			$.ajax({
				url : "{:U('Product/set_attribute')}",
				type: "POST",				
				datatype:"json",
				data:{content:temp,id:{$pid}},
				success: function(msg){
					alert(msg.info);
				}
			  });

		}
	});

	$("#submit2").on("click",function(){
		var nid = $('#newid').val();
		if(nid.length>0)
		{
			$.ajax({
				url : "{:U('Product/copy_attribute')}",
				type: "POST",				
				datatype:"json",
				data:{newid:nid,id:{$pid}},
				success: function(msg){
					alert(msg.info);
					inti();
				}
			  });

		}
	});
	function inti(){
	$.ajax({
		url:"{:U('Product/get_attribute')}",
		datatype:"json",
		type: "POST",
		data:{id:{$pid}},
		success : function(data){
			var $content = $("#content");
		 	$content.empty();
			if(data.info=="no"){
				$content.html("<span>加载失败</span>");	
			}else{
				$content.html(draw(data.data));									
			}			
		}
   });
   };
   inti();
});

</script>
</body>
</html>